package org.jeecg.trace.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.trace.dto.PackageBoxDTO;
import org.jeecg.trace.dto.PackageProductDTO;
import org.jeecg.trace.service.PackageTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags = "产品包装追溯")
@RestController
@RequestMapping("/trace/packageTrace")
@Slf4j
public class PackageTraceController {
    @Autowired
    private PackageTraceService packageTraceService;
    /**
     * 根据参数查询箱\盒包装列表信息
     *
     * @param map
     * @return
     */
    @ApiOperation(value = "序列号列表-分页列表查询", notes = "序列号列表-分页列表查询")
    @GetMapping(value = "/listBoxPackage")
    @DS("#header.his")
    public Result<IPage<PackageBoxDTO>> listBoxPackage(@RequestParam Map<String, String> map,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
        Page<PackageBoxDTO> page = new Page<>(pageNo, pageSize);
        IPage<PackageBoxDTO> pageList = packageTraceService.listBoxPackage(page,map);
        return Result.OK(pageList);
    }


    /**
     * 根据参数查询箱\盒包装列表信息
     *
     * @param lotNo
     * @return
     */
    @ApiOperation(value = "序列号列表-分页列表查询", notes = "序列号列表-分页列表查询")
    @GetMapping(value = "/unbind")
    @DS("C8_SEED")
    public Result unbind(@RequestParam String unitsn) {
        packageTraceService.unbindPackage(unitsn);
        return Result.OK("已删除！重启产线生效！");
    }

    /**
     * 根据参数查询包装介质内产品列表
     *
     * @param map
     * @return
     */
    @ApiOperation(value = "序列号列表-分页列表查询", notes = "序列号列表-分页列表查询")
    @GetMapping(value = "/listProductPackage")
    @DS("#header.his")
    public Result<IPage<PackageProductDTO>> listProductPackage(@RequestParam Map<String, String> map,
                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        HttpServletRequest req) {
        Page<PackageProductDTO> page = new Page<>(pageNo, pageSize);
        IPage<PackageProductDTO> pageList = packageTraceService.listProductPackage(page,map);
        return Result.OK(pageList);
    }

}
